#include "mainscene.h"
#include "ui_mainscene.h"
#include <QPainter>
#include "mybutton.h"
#include <QTimer>
#include "chooselevelscene.h"
#include <QSoundEffect>>
mainscene::mainscene(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::mainscene)
{
    ui->setupUi(this);
    this->setFixedSize(320,588);
    this->setWindowIcon(QPixmap(":/res/Coin0001.png"));
    this->setWindowTitle("翻金币");
    connect(ui->actionexit,&QAction::triggered,[=](){this->close();});
    mybutton *stbtn=new mybutton(":/res/MenuSceneStartButton.png");
    stbtn->setParent(this);
    stbtn->move(this->width()*0.5-stbtn->width()*0.5,this->height()*0.7);
    chooselevelscene *choosescene=new chooselevelscene;
    QSoundEffect *startsound = new QSoundEffect(this);
    /*startsound->setSource(QUrl::fromLocalFile(":/res/TapButtonSound.wav"));
    startsound->play();*/ //开始音效
    connect(stbtn,&mybutton::clicked,[=](){
        stbtn->zoom1();
        stbtn->zoom2();
        startsound->setSource(QUrl::fromLocalFile(":/res/TapButtonSound.wav"));
        startsound->play(); //开始音效
        QTimer::singleShot(500,this,[=](){
            this->hide();
            choosescene->show();
        });
    });

    connect(choosescene,&chooselevelscene::chooseSceneBack,[=](){
        this->show();
    });
}

mainscene::~mainscene()
{
    delete ui;
}

void mainscene::paintEvent(QPaintEvent *){
    QPainter painter(this);
    QPixmap pix;
    pix.load(":/res/PlayLevelSceneBg.png");
    painter.drawPixmap(0,0,this->width(),this->height(),pix);
    pix.load(":/res/Title.png");
    pix = pix.scaled(pix.width()*0.5,pix.height()*0.5);
    painter.drawPixmap(10,30,pix.width(),pix.height(),pix);

}
